package com.situ.water_Invoice.controller;


import com.situ.water_Invoice.mapper.IvArchiveMapper;
import com.situ.water_Invoice.mapper.IvIninvoiceMapper;
import com.situ.water_Invoice.mapper.IvInvoiceMapper;
import com.situ.water_Invoice.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@RestController
//@RequestMapping("/iv-archive")
public class IvArchiveController {
    @Autowired
    IvArchiveMapper mapper;
    @Autowired
    IvIninvoiceMapper ivIninvoiceMapper;
    @Autowired
    IvInvoiceMapper ivInvoiceMapper;

    @ResponseBody
    @RequestMapping("FPJP") //发票交票情况查询
    public List<FPJP> FPJP(){
        List<FPJP> list = mapper.FPJP();
        list.forEach(System.out::println);
        return list;
    }

    //发票出库_获取发票类型
    @ResponseBody
    @RequestMapping("/FPJP_FPLX")
    public String FPCK_FPLX(IvArchive ivArchive) {
        System.out.println("aaa");
        JPTYPE jptype = ivIninvoiceMapper.jptype(ivArchive.getStartNo(), ivArchive.getEndNo());
        //System.out.println(jptype.getInvoiceType()+" iv_ID"+jptype.getID()+
         //       " "+jptype.getInID()+" "+jptype.getEmpNmae());
        String str=null;
        if (jptype == null) {
            str="true";
        } else {
            if (jptype.getInvoiceType() == 0) {
                System.out.println("普通发票");
                str="普通发票";
            }
            if (jptype.getInvoiceType() == 1) {
                System.out.println("增值税发票");
                str="增值税发票";
            }
            System.out.println("false");
        }
        str +=","+ jptype.getID()+","+jptype.getInID()+","+jptype.getEmpNmae();
        return str;
    }


    //比较发票号码是否存在  --  存在代表可以交票
    @PostMapping("/iv-Ar-StartNo")
    public int bj(String StartNo){
        IvArchive ivar = mapper.queryId(StartNo);
        int str = 0;
        if(ivar == null){
            str=1;
        }else{
            str=0;
        }
        return str;//ResponseData.ok().putDataValue("list", list);
    }

    //发票交票
    @PostMapping("/iv-Aradd")
    public int  addIvOutinvoice(IvArchive ivArchive){
        System.out.println(ivArchive.getStartNo()+"  empid="+ivArchive.getEmpID());
        int add = mapper.addIvArchive(ivArchive);
        if(add>0){
            System.out.println("交票成功！");
        }else{
            System.out.println("交票失败!");
        }
        return add;
    }

    //把id添加到 Iv_Invoice表中
    @PostMapping("/getArID")
    public int add(){
        IvArchive ivinid = mapper.Ivinid();
        System.out.println(ivinid.getId());
        IvInvoice list = ivInvoiceMapper.querynullArchiveID();
        System.out.println(list.getInvoiceNo());
        ivInvoiceMapper.updateInInvoiceArchiveID(ivinid.getId(), list.getInvoiceNo());
        int o=0;
        return o;
    }


}

